#include <iostream>
#include <string>
#include <algorithm> 
using namespace std;

int main() {
    int M, N, flag = 0;
    string str = "0123456789ABCDEF";
    string ans;
    cin >> M >> N;
    if (M < 0)
    {
        M = -M;
        flag = 1;
    }
    while (M)
    {
        ans += str[M % N];
        M /= N;
    }
    if (flag)
        ans += '-';
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}